package com.woniu.controller;

import com.woniu.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户管理")
public class UserController extends BaseController{

    @ApiOperation("模拟登录")
    @PostMapping("/login")
    public Result login(@RequestBody Map<String, String> params){
        log.debug("进入登录方法===========");
        Map<String, String> map = new HashMap<>();
        map.put("token", params.get("username"));
        return toDataResult(map);
    }

    @GetMapping("/info")
    public Result info(String token){
        log.debug("token = " + token);
        Map<String, Object> map = new HashMap<>();
        map.put("name", token);
        map.put("avatar", "https://img1.baidu.com/it/u=2838100141,2488760005&fm=253&app=138" +
                "&size=w931&n=0&f=JPEG&fmt=auto?sec=1663520400&t=7091611ba73832e3566f237c4e9a09ed");
        map.put("roles", new String[]{"admin", "teacher", "student"});
        return toDataResult(map);
    }

    @PostMapping("/logout")
    public Result logout(){
        return success();
    }
}
